import {RouteRecordRaw} from "vue-router";
import {RouteConstant} from "@/constants/route";

export const Layout = () => import("@/layout/index.vue");
export const Home = () => import("@/views/home/index.vue");
export const Time = () => import("@/views/time/index.vue");
export const TemplateOne = () => import("@/views/templateOne/index.vue");
export const InnerLink = () => import("@/views/innerLink/index.vue");
export const LevelOne = () => import("@/views/nested/level1/index.vue");
export const LevelTwo = () => import("@/views/nested/level1/level2/index.vue");
export const NotFound = () => import("@/views/error/404/index.vue");
export const SERVER_ERROR = () => import("@/views/error/500/index.vue");
// 首页路由配置 : HOME_ROUTE_RAW 为 children 不需要 '/'
export const HOME_ROUTE_RAW: RouteRecordRaw = {
    path: RouteConstant.HOME_PATH.substring(1),
    name: "Home",
    component: Home,
    meta: {
        title: '首页',
        icon: 'vite',
        affix: true,
        keepAlive: true,
        hidden: false,
    }
}
// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
    {
        path: "/",
        name: "/",
        component: Layout,
        meta: {
            hidden: false,
        },
        redirect: RouteConstant.HOME_PATH,
        children: [
            HOME_ROUTE_RAW,
            {
                path: "404",
                name: "NotFound",
                component: NotFound,
                meta: {
                    title: "404",
                    hidden: true,
                    keepAlive: false
                }
            }, {
                path: "500",
                name: "SERVER_ERROR",
                component: SERVER_ERROR,
                meta: {
                    title: "500",
                    hidden: true,
                    keepAlive: false
                }
            }]
    },
    {
        path: "/redirect",
        component: Layout,
        meta: {hidden: true},
        redirect: "/redirect/",     // /redirect/ 重定向到表示主页
        children: [
            {
                path: "/redirect/:path(.*)",
                name: "Redirect",
                meta: {hidden: true},
                component: () => import("@/views/redirect/index.vue"),
            },
        ],
    },
    {
        path: "/time",
        name: "Time",
        component: Time,
        meta: {
            title: '组件切换测试',
            icon: 'el-icon-check',
            keepAlive: true,
            hidden: false,
        }
    },
    {
        path: "/template_one",
        name: "/template_one",
        component: Layout,
        meta: {
            hidden: false
        },
        redirect: "/template_one/one",
        children: [
            {
                path: "one",
                name: "TemplateOne",
                component: TemplateOne,
                meta: {
                    title: '高度 / 动画测试',
                    icon: 'el-icon-check',
                    affix: false,
                    keepAlive: true,
                    hidden: false,
                },
            }
        ]
    },
    {
        path: "/template_two",
        component: Layout,
        meta: {
            title: '链接测试',
            icon: 'el-icon-check',
            keepAlive: true,
            hidden: false,
            showSingleChildren: true
        },
        redirect: "https://juejin.cn/spost/7362783257257721856",
        children: [
            {
                path: "https://juejin.cn/spost/7362783257257721856",
                name: "https://juejin.cn/spost/7362783257257721856",
                component: Layout,
                meta: {
                    title: '外链测试',
                    icon: 'el-icon-check',
                    hidden: false,
                },
            },
            {
                path: "inner_link",
                name: "InnerLink",
                component: InnerLink,
                meta: {
                    title: '内链测试',
                    icon: 'el-icon-check',
                    hidden: false,
                    keepAlive: true,
                },
            }
        ]
    },
    {
        path: "/nested",
        name: "/nested",
        component: Layout,
        meta: {
            title: '不展示单个子元素',
            icon: 'el-icon-check',
            keepAlive: true,
            hidden: false,
        },
        redirect: "/nested/level1",
        children: [
            {
                path: "level1",
                name: "LevelOne",
                component: LevelOne,
                meta: {
                    title: '层级一',
                    icon: 'el-icon-check',
                    keepAlive: true,
                    hidden: false,
                    breadcrumb: false
                },
                redirect: "/nested/level1/level2",
                children: [
                    {
                        path: "level2",
                        name: "LevelTwo",
                        component: LevelTwo,
                        meta: {
                            title: '层级二',
                            icon: 'el-icon-check',
                            keepAlive: true,
                            hidden: false,
                        },
                    },
                ]
            }
        ]
    },
    {
        path: "/nested/showChildren",
        name: "/nested/showChildren",
        component: Layout,
        meta: {
            title: '展示单个子元素',
            icon: 'el-icon-check',
            keepAlive: true,
            hidden: false,
            showSingleChildren: true
        },
        redirect: "/nested/showChildren/level1",
        children: [
            {
                path: "level1",
                name: "ShowChildrenLevelOne",
                component: LevelOne,
                meta: {
                    title: '层级一',
                    icon: 'el-icon-check',
                    keepAlive: true,
                    hidden: false,
                    showSingleChildren: true
                },
                redirect: "/nested/showChildren/level1/level2",
                children: [
                    {
                        path: "level2",
                        name: "ShowChildrenLevelTwo",
                        component: LevelTwo,
                        meta: {
                            title: '层级二',
                            icon: 'el-icon-check',
                            keepAlive: true,
                            hidden: false,
                        },
                    },
                ]
            }
        ]
    }
]
